<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ include file="/commons/global.jsp"%>

<html>
<head>
  <title>${sys_name}</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <meta http-equiv="Cache-Control" content="no-siteapp" />

  <%@ include file="/commons/head.jsp"%>

  <script type="text/html" id="qxclass">
    {{#  if(d.qxclass === '1'){ }}
    <span style="color: #2016f5;">管理员</span>
    {{# } }}
    {{#  if(d.qxclass === '2'){ }}
    <span style="color: #25f5e6;"></span>
    {{# } }}
    {{#  if(d.qxclass === '3'){ }}
    <span style="color: #11a8f5;">操作手</span>
    {{# } }}
  </script>

  <script type="text/html" id="zyzId">
    {{#  if(d.zyzId === '1'){ }}
    <span style="color: #F581B1;">计算机</span>
    {{# } }}
    {{#  if(d.zyzId === '2'){  }}
    <span style="color: #F58100;">经济</span>
    {{# } }}
    {{#  if(d.zyzId === '3'){ }}
    <span style="color: #F58150;">文学</span>
    {{# } }}
  </script>

    <script type="text/html" id="barDemo">
        <a title="编辑" href="javascript:;" onclick="member_edit('编辑','member-edit.html?{{d.userId}}','4','','510')"
           class="ml-5" style="text-decoration:none">
            <i class="layui-icon">&#xe642;</i>
        </a>
        <a style="text-decoration:none"  onclick="member_password('修改密码','${basePath}user/pass?userId={{d.userId}}','600','400')"
           href="javascript:;" title="修改密码">
            <i class="layui-icon">&#xe631;</i>
        </a>
        <a title="删除" href="javascript:;" onclick="member_del(this,'{{d.userId}}')"
           style="text-decoration:none">
            <i class="layui-icon">&#xe640;</i>
        </a>
 </script>


</head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">首页</a>
        <a href="#">用户列表</a>

      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form layui-col-md12 x-so">

                <input type="text" name="userCode" id="suserCode" placeholder="用户名" autocomplete="off" class="layui-input">
                <input type="text" name="userName" id="suserName" placeholder="姓名" autocomplete="off" class="layui-input">
                <button class="layui-btn"      lay-filter="search" id="search"><i class="layui-icon">&#xe615;</i></button>
            </form>
        </div>

      <xblock>

        <button class="layui-btn" onclick="x_admin_show('添加用户','${basePath}user/add',800,500)"><i class="layui-icon"></i>添加用户</button>

      </xblock>

      <table class="layui-table"    id="userTable" >

      </table>

    </div>
    <script>
        // 用户-编辑
        function member_edit (title,url,id,w,h) {

             x_admin_show(title,url,w,h);
        }
        /*密码-修改*/
        function member_password(title,url,w,h){
            x_admin_show(title,url,w,h);
        }
        /*用户-删除*/
        function member_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                //发异步删除数据
                var para={userId:id};

                $.post('<%=basePath%>user/delete',para,function(res){
                    if(res.flag){

                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                        location.replace(location.href);

                    }else{
                        layer.msg(res.msg, {time: 2000});
                        return false;
                        //  x_admin_close();
                    }
                },'json');

            });


        }


      layui.use(['table','form'], function(){
          var mytable = layui.table;
          var form = layui.form;
          var tableIns =  mytable.render({
               elem: '#userTable'
              ,id: 'userTable'
              ,height: 350,
              dataType: "json"
              , type:"post"
              ,  async:false
              ,url: '<%=basePath%>user/getcondition' //数据接口
              ,page: true //开启分页
               ,request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
              }

              ,cols: [[ //表头

                  {field: 'userCode', title: '用户名', width:180, sort: true }
                  ,{field: 'userName', title: '姓名', width:180, sort: true }
                  ,{field: 'userdept', title: '所在单位', width:180, sort: true}
                  ,{field: 'qxclass', title: '角色类别', width:180,templet: '#qxclass'}
                  ,{field: 'zyzId', title: '所在专业组',width:180,   sort: true,templet: '#zyzId'}
               ,  { field: '',  title:'操作', align:'center',width:240, templet: '#barDemo'}
                ]]


          });



          $('#search').on('click', function(){
              var userCode = $('#suserCode');
              var userName = $('#suserName');
            //执行重载
              tableIns.reload( {
                  where: {
                       userCode: userCode.val(),
                       userName: ''+userName.val()
                  }
              });
              return false;

          });



      });



    </script>


  </body>

</html>